package org.ichow.scenegame.notis
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author M.ichow
	 */
	public class HelpNoti extends BaseNoti
	{
		//关闭按钮
		private var __closeBtn : DisplayObject;
		//遮罩宽度
		private var _width : Number;
		//遮罩高度
		private var _height : Number;
		//遮罩
		private var __maskMc : DisplayObject;
		//帮助
		private var __helpMc : DisplayObjectContainer;
		
		public function HelpNoti()
		{
			super();
		}
		
		override protected function init() : void
		{
			super.init();
			if ( _noti is DisplayObjectContainer )
			{
				__helpMc = ( _noti as DisplayObjectContainer ).getChildByName( "help_mc" ) as DisplayObjectContainer;
				__closeBtn = __helpMc.getChildByName( "close_btn" );
				__maskMc = ( _noti as DisplayObjectContainer ).getChildByName( "mask_mc" );
			}
			_noti.visible = false;
			_container.addChild( _noti );
		}
		
		override protected function addListeners() : void
		{
			super.addListeners();
			if ( __closeBtn && !__closeBtn.hasEventListener( MouseEvent.MOUSE_UP ) )
				__closeBtn.addEventListener( MouseEvent.MOUSE_UP , onCloseMouseClick );
		}
		
		override protected function removeListeners() : void
		{
			super.removeListeners();
			__closeBtn.removeEventListener( MouseEvent.MOUSE_UP , onCloseMouseClick );
		}
		
		override public function active() : void
		{
			_noti.visible = true;
			super.active();
		}
		
		override public function cancel() : void
		{
			_noti.visible = false;
			removeListeners();
		}
		
		/**
		 * 关闭
		 * @param	e
		 */
		private function onCloseMouseClick( e : MouseEvent ) : void
		{
			dispatchEvent( new Event( "close" ) );
		}
		
		/**
		 * 高度设置
		 */
		public function get height() : Number
		{
			return _height;
		}
		
		public function set height( value : Number ) : void
		{
			_height = value;
			if ( __maskMc )
			{
				__maskMc.height = _height;
				__helpMc.y = Math.floor( _height - __helpMc.height ) / 2;
			}
		}
		
		/**
		 * 宽度设置
		 */
		public function get width() : Number
		{
			return _width;
		}
		
		public function set width( value : Number ) : void
		{
			_width = value;
			if ( __maskMc )
			{
				__maskMc.width = _width;
				__helpMc.x = Math.floor( _width - __helpMc.width ) / 2;
			}
		
		}
	
	}

}